from search.utils import infinity
# -*- coding:utf-8 -*-
"""
Created on Apr 21, 2011

@author: bob
"""
def manhattan(pointA, pointB):
        return abs(pointA[0]-pointB[0])+abs(pointA[1]-pointB[1])

def bestRobotFromPile(pileLoc, robots):
    '''
    @param pileLoc: a pair - location
    @param robots: tuple with robots locations  
    '''
    minDist = infinity
    bestRobot = None
    for r in robots:
        if (manhattan(pileLoc, r)<minDist):
            minDist = manhattan(pileLoc, r)
            bestRobot = r
            if (minDist == 1):
                break    
    return bestRobot,minDist
    
def bestPileFromRobot(robotLoc, piles):
    minDist = infinity
    bestPile = None
    for p in piles:
        if (manhattan(p, robotLoc)<minDist):
            minDist = manhattan(p, robotLoc)
            bestPile = p
            if (minDist == 1):
                break    
    return bestPile,minDist